using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Toast.Core.Interfaces;

namespace Toast
{
    public abstract class ContentCollectionBase<TContent> : List<TContent> where TContent : IContent
    {
        // TODO: Fix this smell
        public new ContentCollectionBase<TContent> Add(TContent content)
        {
            if (!Contains(content) && content != null)
                base.Add(content);
            return this;
        }

        public ContentCollectionBase<TContent> Add(IEnumerable<TContent> contentItems)
        {
            foreach (var content in contentItems)
                Add(content);

            return this;
        }

        protected ContentCollectionBase()
        {
        }

        protected ContentCollectionBase(IEnumerable<TContent> contentItems)
        {
            foreach (var content in contentItems)
                Add(content);
        }

        public ReadOnlyCollection<T> ContentOfType<T>() where T : IContent
        {
            return new ReadOnlyCollection<T>(this.Where(x => x is T).Cast<T>().ToList());
        }
    }

    public class ContentCollection : ContentCollectionBase<IContent>
    {
    }
}